package com.internship.javawebinternship.repository;

import com.internship.javawebinternship.entity.LeaveApply;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface LeaveApplyRepository extends JpaRepository<LeaveApply, String> {


    public List<LeaveApply> findByStunoOrderByStateAsc(String no);

    @Transactional
    @Modifying
    public int deleteByApplyid(int applyid);

    @Transactional
    @Modifying
    @Query(value = "select * from covid19.leave_apply ORDER BY `stuNo` asc ",nativeQuery = true)
    public List<LeaveApply> findAll();

    @Transactional
    @Modifying
    @Query(value = "select applyId,leave_apply.stuNo,leaveTime,reason,travelPath,traffic,`state`,comment FROM student_info,leave_apply,tutor_classes WHERE empNo = ?1 AND student_info.stuNo = leave_apply.stuNo AND student_info.college = tutor_classes.college AND student_info.profession = tutor_classes.profession   AND student_info.grade = tutor_classes.grade  AND student_info.classes = tutor_classes.classes ORDER BY `state` asc",nativeQuery = true)
    public List<LeaveApply> findPart(String empNo);


    public List<LeaveApply> findByApplyid(int applyid);

}
